/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication2;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author ppfaff
 */
public class propertyParse {
    public static void main(String[] args) throws FileNotFoundException, IOException{
        
    System.out.println("Properties Run!");   //debug message
    fileFind fileFind1 = new fileFind(); //calls fileFind.java class
    fileFind1.init(); //initiates the find and read process
    property tempObj = new property(); // creates a temporary 'property' object that will be used during the iterations
    Double totalValue = 0.00; 
    Integer totalListings = 0;
    Iterator<property> i = fileFind1.properties.iterator();
    ArrayList<Integer> propertyIDs= new ArrayList<Integer>();        
        while(i.hasNext()){
            tempObj = i.next();
            totalValue = totalValue + tempObj.getPropertyValue();
            totalListings++;
            propertyIDs.add(tempObj.getPropertyNumber());
        }
    Collections.sort(propertyIDs);
    Scanner console = new Scanner(System.in);
    System.out.print("Output file: ");
    String outputFileName = console.next();
    BufferedWriter out = null;
    out = new BufferedWriter(new FileWriter(outputFileName));

        try {   
            out.write("Total properties listed: "+totalListings);
            out.newLine();
            out.write("Total value of properties listed: "+totalValue);
            out.newLine();
            out.newLine();
            for(Integer id : propertyIDs){
                out.write(id.toString());
                out.newLine();
                }
        }
        catch (IOException ex) {
            Logger.getLogger(propertyParse.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally{
            out.flush();
            out.close(); 
        }
    }
}
